package tinynio;

import java.io.IOException;
import java.net.SocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;

public class ServerSocketCommunicator extends AbstractCommunicator {

	private Configuration config;

	public ServerSocketCommunicator(Select select) throws IOException {
		super(select, ServerSocketChannel.open(), SelectionKey.OP_ACCEPT);
	}

	@Override
	public void connect(SocketAddress remote) throws IOException {
		throw new UnsupportedOperationException();
	}

	@Override
	public void bind(SocketAddress local) throws IOException {
		register();
		channel().socket().bind(local);
	}

	@Override
	public void write(Object obj) throws IOException {
		throw new UnsupportedOperationException();
	}

	@Override
	public void flush() throws IOException {
		throw new UnsupportedOperationException();
	}

	@Override
	public void read() throws IOException {
		throw new UnsupportedOperationException();
	}

	@Override
	public ServerSocketChannel channel() {
		return (ServerSocketChannel) super.channel();
	}

	@Override
	public boolean isActive() {
		return channel().socket().isBound();
	}

	@Override
	public void config(Configuration config) {
		this.config = config;
	}

	public void config(SocketCommunicator sc) {
		sc.config(config);
	}
}
